
var locationDao = require('../dao/LocationDao');
var async = require('async');


module.exports.getLocation= function (req,callback){
    async.parallel({
        allCity:function(callback){
            locationDao.getAllCity(function(data){
                if(data.isSuccess){
                    var allCity=new Array();
                    var index;
                    var city;
                    var hotCity = new Array() ;
                    data.rows.forEach(
                        function(val) {
                            if(index  !== val.py){
                                index = val.py;
                                city = new Array();
                                allCity.push({
                                    'index':index,
                                    'city':city
                                })
                            }
                            if(val.hot_flag == 1){
                                hotCity.push(val)
                            }
                            city.push(val);
                        });
                    callback(null,allCity)
                }
            });
        },
        hotCity:function (callback) {
            locationDao.getHotCity(function(data){
                if(data.isSuccess){
                    var hotCity = new Array() ;
                    data.rows.forEach(function (val) {
                        hotCity.push(val);
                    });
                    callback(null,hotCity);
                }
            })

        }

    } ,function(err,result) {
        if (err) {
            resultData={
                layout: false,
                message: 'error',
                status: 'error'
            };
        }else{
            resultData = {
                title:'城市选择',
                layout: false,
                status:"success",
                message:"success",
                allCity:result.allCity,
                hotCity:result.hotCity
            };
        }
        callback(resultData);
    });
};